﻿
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System;

using System.Data.SqlClient;
using System.Web.Services;

using System.Data;
using System.Configuration;
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.IO;
using System.Data.SqlClient;
using System.Drawing;
using System.Net.Mail;

using System.Web.Services;


public partial class admin_view_buy : System.Web.UI.Page
{
    string ss;
    protected void Page_Load(object sender, EventArgs e)
    {
        Session["p_id"] = Request.QueryString["id"].ToString();
        BindGridviewData();
        Label67.Text = Session["p_id"].ToString();

        if (Session["email"] == null)
        {
            Session["email"] = "admin";
        }
        ss = Request.QueryString["id"].ToString (); 
        Label1.Text = Session["email"].ToString();

        if (Page.IsPostBack)
        {
        }
        else
        {
            string str = Request.QueryString["id"].ToString(); ; 
            // Image1 .ImageUrl ="property.ashx?p_id=" + str.ToString();
            SqlConnection conn = null;
            conn = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnStr"].ConnectionString);


            conn.Open();
            SqlCommand scmd = new SqlCommand("SELECT * FROM property_buy where p_id='" + Request.QueryString["id"] + "'", conn);

            SqlDataReader dr = scmd.ExecuteReader();
            if (dr.Read())
            {
                //Client Details 
                txtclient_fullname1.Text = dr[8].ToString();
                txtclient_fullname2.Text = dr[9].ToString();
                lblssn.Text = dr[10].ToString();
                lblphone.Text = dr[11].ToString();
                lblctype.Text = dr[6].ToString();

                //End Client Details 

                //Client Address
                lblsteet.Text = dr[12].ToString();
                lblhouse.Text = dr[13].ToString();
                lblneigh.Text = dr[14].ToString();
                lblcity.Text = dr[15].ToString();
                lblcount.Text = dr[16].ToString();
                lblzip.Text = dr[17].ToString();
                lblptype.Text = dr[29].ToString();
                lblptype1.Text = dr[30].ToString();
                lblpcondi.Text = dr[31].ToString();
                lblpcondi1.Text = dr[32].ToString();
                Label68.Text = dr[33].ToString();
                Label69.Text = dr[34].ToString();
                Label70.Text = dr[35].ToString();
                Label71.Text = dr[36].ToString();
                Label72.Text = dr[37].ToString();
                Label73.Text = dr[38].ToString();
                Label74.Text = dr[39].ToString();
                Label75.Text = dr[40].ToString();
                Label76.Text = dr[41].ToString();
                Label77.Text = dr[42].ToString();
                Label78.Text = dr[43].ToString();
                Label79.Text = dr[44].ToString();
                Label80.Text = dr[45].ToString();
                Label81.Text = dr[46].ToString();
                Label82.Text = dr[47].ToString();
                Label83.Text = dr[51].ToString();
                Label84.Text = dr[52].ToString();
                Label85.Text = dr[53].ToString();
                Label86.Text = dr[54].ToString();
                Label87.Text = dr[55].ToString();
                Label88.Text = dr[56].ToString();
                Label89.Text = dr[57].ToString();
                Label90.Text = dr[58].ToString();
                Label91.Text = dr[59].ToString();
                Label92.Text = dr[60].ToString();
                Label93.Text = dr[61].ToString();
                Label94.Text = dr[62].ToString();
                Label95.Text = dr[63].ToString();
                Label96.Text = dr[64].ToString();

                lblssn.Text = dr[10].ToString();
                lblcity.Text = dr[16].ToString();





///////////////////////////////////////////////////////////////////////
                if (lblctype.Text == "בחר" || lblctype.Text == "שדה למילוי עצמי")
                {
                    lblctype.Text = "-";
                }

                else
                {
                    lblctype.Text = dr[6].ToString();
                }

/////////////////////////////////////////////////////////////////////////
                if (lblptype.Text == "בחר" || lblptype.Text == "שדה למילוי עצמי")
                {
                    lblptype.Text = "-";
                }

                else
                {
                    lblptype.Text = dr[29].ToString();
                }

/////////////////////////////////////////////////////////////////////////

                if (lblpcondi.Text == "בחר" || lblpcondi.Text == "שדה למילוי עצמי")
                {
                    lblpcondi.Text = "-";
                }

                else
                {
                    lblpcondi.Text = dr[31].ToString();
                }

/////////////////////////////////////////////////////////////////////////

                if (Label68.Text == "בחר" || Label68.Text == "שדה למילוי עצמי")
                {
                    Label68.Text = "-";
                }

                else
                {
                    Label68.Text = dr[33].ToString();
                }

/////////////////////////////////////////////////////////////////////////
                if (Label70.Text == "בחר" || Label70.Text == "שדה למילוי עצמי")
                {
                    Label70.Text = "-";
                }

                else
                {
                    Label70.Text = dr[35].ToString();
                }

/////////////////////////////////////////////////////////////////////////
                if (Label74.Text == "בחר" || Label74.Text == "שדה למילוי עצמי")
                {
                    Label74.Text = "-";
                }

                else
                {
                    Label74.Text = dr[39].ToString();
                }

/////////////////////////////////////////////////////////////////////////
                if (Label76.Text == "בחר" || Label76.Text == "שדה למילוי עצמי")
                {
                    Label76.Text = "-";
                }

                else
                {
                    Label76.Text = dr[41].ToString();
                }

/////////////////////////////////////////////////////////////////////////
                if (Label79.Text == "בחר" || Label79.Text == "שדה למילוי עצמי")
                {
                    Label79.Text = "-";
                }

                else
                {
                    Label79.Text = dr[44].ToString();
                }

/////////////////////////////////////////////////////////////////////////
                if (Label84.Text == "בחר" || Label84.Text == "שדה למילוי עצמי")
                {
                    Label84.Text = "-";
                }

                else
                {
                    Label84.Text = dr[52].ToString();
                }

/////////////////////////////////////////////////////////////////////////
                if (Label86.Text == "בחר" || Label86.Text == "שדה למילוי עצמי")
                {
                    Label86.Text = "-";
                }

                else
                {
                    Label86.Text = dr[54].ToString();
                }

/////////////////////////////////////////////////////////////////////////
                if (Label88.Text == "בחר" || Label88.Text == "שדה למילוי עצמי")
                {
                    Label88.Text = "-";
                }

                else
                {
                    Label88.Text = dr[56].ToString();
                }

/////////////////////////////////////////////////////////////////////////
                if (Label90.Text == "בחר" || Label90.Text == "שדה למילוי עצמי")
                {
                    Label90.Text = "-";
                }

                else
                {
                    Label90.Text = dr[58].ToString();
                }

/////////////////////////////////////////////////////////////////////////
                if (Label72.Text == "בחר" || Label90.Text == "שדה למילוי עצמי")
                {
                    Label72.Text = "-";
                }

                else
                {
                    Label72.Text = dr[37].ToString();
                }

                /////////////////////////////////////////////////////////////////////////
            }


            dr.Close();
        }
    }


    protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
    {




        if (e.CommandName == "view")
        {

            //Label1.Text = "hello";
            int index = Convert.ToSByte(e.CommandArgument);

            GridViewRow row = GridView2.Rows[index];
            SqlDataAdapter adp = new SqlDataAdapter();
            SqlCommand cmd1 = new SqlCommand();
            DataSet ds = new DataSet();


            SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["Connstr"].ConnectionString);

            con.Open();

            SqlCommand objectvalue = new SqlCommand("", con);
            cmd1.Connection = con;



            SqlCommand dmc = new SqlCommand("select p_id from property_buy where p_id='" + row.Cells[0].Text + "'", con);

            dmc.ExecuteNonQuery();
            Session["p_id"] = row.Cells[0].Text;

            con.Close();
            // Response.Write(Session["p_id"]);
            // Response.Write(@"<script language='javascript'>alert('clent has been selected')</script>");
            Response.Redirect("view-task.aspx");
            // con.Close();


        }
    }


    protected void Save_Click(object sender, EventArgs e)
    {

    }
    protected void SearchButton_Click(object sender, EventArgs e)
    {


        //  string pageurl="Default.aspx?Id=6&RollNo=15";

        //Response.Write(<script> window.open( ‘"+pageurl+"’,'_blank' ); </script>);
        //Response.End();
    }

    protected void LinkButton1_Click(object sender, System.EventArgs e)
    {
        Session.Abandon();
        Response.Redirect("../admin.aspx");
    }
    private void BindGridviewData()
    {
        SqlConnection con = null;
        con = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnStr"].ConnectionString);

        con.Open();
        SqlCommand cmd = new SqlCommand("select * from files where id='" + Request.QueryString["id"] + "'", con);
        SqlDataAdapter da = new SqlDataAdapter(cmd);
        DataSet ds = new DataSet();
        da.Fill(ds);

        gvDetails.DataSource = ds;
        gvDetails.DataBind();

        con.Close();
    }
    protected void lnkDownload_Click(object sender, EventArgs e)
    {
        LinkButton lnkbtn = sender as LinkButton;
        GridViewRow gvrow = lnkbtn.NamingContainer as GridViewRow;
        string file_path = gvDetails.DataKeys[gvrow.RowIndex].Value.ToString();
        Response.ContentType = "image/jpg";
        Response.AddHeader("Content-Disposition", "attachment;filename=\"" + file_path + "\"");
        Response.TransmitFile(Server.MapPath(file_path));
        Response.End();
    }

}